package com.mmy.dao.hotel;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.hotel.THotelRoom;

public interface THotelRoomRepository extends JpaRepository<THotelRoom, Integer> {

	/**
	 * 获得最大房间编号
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 dingxd
	 * @date 创建日期 2020.11.17
	 */
	@Query(value = "SELECT MAX(iRoomID) FROM tHotelRoom WHERE LEFT(iRoomID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxRoomID();

	/* 创建房间信息 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tHotelRoom(iRoomID, cRoomName, iHotelID, bRoomType, iRoomSize, iOnFloor, bWindows, bWifi, bNetwork, bBreakfast, iNumber, cImgPath, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int roomID);

	/**
	 * 函数功能说明： 进入后台酒店信息页面查询酒店房间详情信息
	 *
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.12.24
	 */
	@Query(value = "select * from tHotelRoom where iHotelID=?1", nativeQuery = true)
	List<THotelRoom> findByHotelID(int iHotelID);

	/* 通过房间编号查找 */
	@Query(value = "select * from tHotelRoom where iRoomID=?1", nativeQuery = true)
	THotelRoom findByiRoomID(int iRoomID);

	/* 删除房间 */
	@Transactional
	@Modifying
	@Query(value = "delete from tHotelRoom where iRoomID in (:iRoomIDs)", nativeQuery = true)
	void deleteChecked(@Param("iRoomIDs") List<Integer> iRoomIDs);

	/* 查询该酒店的房间名称并且去重 */
	/*
	 * @Query(value = "select distinct cRoomName from tHotelRoom where iHotelID=?1",
	 * nativeQuery = true) List<String> getNameByHotelID(int iHotelID);
	 */

}
